package DAO;

import Annotation.DBConnection;
import Domain.UserEntity;
import Util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import java.util.List;

/**
 * Created by studio on 2017/2/22.
 */

@DBConnection.Database(username = "fyb",password = "fanyibin",DBName = "jd")
public class UserDAO {

    private SessionFactory sessionFactory;

    public UserDAO() {//尝试分别读取两个数据库
        this.sessionFactory = HibernateUtil.getSessionFactory(DBConnection.getDBInfo(this.getClass()));
    }

    public Session getSession(){
        return HibernateUtil.getSession();
    }

    public List<UserEntity> getAll(){
        String sql = "select id,username,password,age from UserEntity ";
        return getSession().createQuery(sql).list();
    }
}
